<?php
declare(strict_types=1);
/**
 * 渠道运费模板服务
 */
namespace Service\TemplateService;

use Service\BaseService;
use App\Model\PssModel\TemplateDelivery;
class TemplateDeliveryService extends BaseService
{
    /**
     * 获取默认运费模板信息
     */
    public function getDefaultTemplateInfo()
    {
        $table = TemplateDelivery::instance()->getTable();
        $defaultTemplateInfo = TemplateDelivery::instance()
        ->from("{$table} as td")
        ->select([
            'tda.template_id',
            'tda.init_weight',
            'tda.init_money',
            'tda.increase_weight',
            'tda.increase_money',
        ])
        ->join('template_delivery_area as tda','tda.template_id','=','td.id')
        ->where('tda.is_all_country',1)
        ->first();
        $defaultTemplateInfo = $defaultTemplateInfo ? $defaultTemplateInfo->toArray() : [];
        return $defaultTemplateInfo ? $defaultTemplateInfo : [
            'template_id'       => 1,
            'init_weight'       => 0,
            'init_money'        => 0,
            'increase_weight'   => 0,
            'increase_money'    => 0
        ];
    }
}